package demo10;

class ID implements Cloneable {
    public int id = 21345;

    @Override
    protected Object clone()
            throws CloneNotSupportedException {
        return super.clone();
    }
}
public class Person implements Cloneable{
    public String name;
    public int age;

    public ID i = new ID();

    public Person(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    protected Object clone()
            throws CloneNotSupportedException {
        Person temp  = (Person) super.clone();
        temp.i = (ID) this.i.clone();
        return temp;
        //深拷贝
    }
//    @Override
//    protected Object clone()
//            throws CloneNotSupportedException {
//        return super.clone();
//    //浅拷贝
//    }

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}
